package me.flyray.biz.thymeleaf.modules.goods.biz;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.msg.TableResultResponse;
import com.github.wxiaoqi.security.common.qr.request.QrQueryGoodsParam;

import me.flyray.biz.thymeleaf.modules.goods.entity.QrGoodsInfo;
import me.flyray.biz.thymeleaf.modules.goods.entity.QrGoodsScanningStatistics;
import me.flyray.biz.thymeleaf.modules.goods.mapper.QrGoodsScanningStatisticsMapper;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * 扫描统计
 *
 * @author chj
 * @email ${email}
 * @date 2018-09-28 16:08:28
 */
@Service
public class QrGoodsScanningStatisticsBiz extends BaseBiz<QrGoodsScanningStatisticsMapper,QrGoodsScanningStatistics> {
	
	private static final Logger logger = (Logger) LoggerFactory.getLogger(QrGoodsInfoBiz.class);
	
	
	/**
	 * 
	 * @param param
	 * @return
	 */
	public TableResultResponse<QrGoodsScanningStatistics> queryList(QrQueryGoodsParam param) {
		Example example = new Example(QrGoodsScanningStatistics.class);
		example.setOrderByClause("scanning_time desc");
		Criteria criteria = example.createCriteria();
		if (param.getPlatformId() != null && param.getPlatformId().length() > 0) {
			criteria.andEqualTo("platformId", param.getPlatformId());
		}
		if (param.getMerchantId() != null && param.getMerchantId().length() > 0) {
			criteria.andEqualTo("merchantId", param.getMerchantId());
		}
		if (param.getGoodsId() != null && param.getGoodsId().length() > 0) {
			criteria.andEqualTo("goodsId", param.getGoodsId());
		}
		Page<QrGoodsScanningStatistics> result = PageHelper.startPage(param.getPage(), param.getLimit());
		List<QrGoodsScanningStatistics> list = mapper.selectByExample(example);
		TableResultResponse<QrGoodsScanningStatistics> table = new TableResultResponse<>(result.getTotal(), list);
		return table;
	}
}